package com.da.javatest.leetCode2;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class Code229 {
    public List<Integer> majorityElement(int[] nums) {
        if (nums.length < 1) {
            return new ArrayList<>();
        }
        Map<Integer, Integer> map = new HashMap<>();
        for (int num : nums) {
            map.put(num, map.getOrDefault(num, 0) + 1);
        }
        int max = nums.length / 3 + 1;
        return map.entrySet().stream().filter(m -> m.getValue() >= max).map(x -> x.getKey())
                .collect(Collectors.toList());
    }
}
